package main

import "fmt"

func main() {
	sl := make([]int, 0, 10)
	var appendFunc = func(s []int) {
		s = append(s, 10, 20, 30)
		fmt.Println("s = ", s) // s =  [10 20 30]
	}
	appendFunc(sl)
	fmt.Println("sl = ", sl)           // sl =  []
	fmt.Println("sl[:10] = ", sl[:10]) // sl[:10] =  [10 20 30 0 0 0 0 0 0 0]

	testa()
}

func testa() {
	sl := make([]int, 0, 2)
	var appendFunc = func(s []int) {
		s = append(s, 10, 20, 30) // 发生了扩容，s和sl指向的数据不是同一个内存地址了
		fmt.Println("s = ", s)    // s =  [10 20 30]
	}
	appendFunc(sl)
	fmt.Println("sl = ", sl)          // sl =  []
	fmt.Println("sl[:10] = ", sl[:2]) // sl[:10] =  [0 0]
}
